package com.ydc.ln.tutorial.gui.test.comp;

import javax.swing.ButtonGroup;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JRadioButtonMenuItem;

import com.ydc.ln.tutorial.gui.MyJFrame;

/**
 * 
 * @author ydc
 * @date 下午1:34:09 2013-5-19
 */
public class MenuFrame extends MyJFrame {

    /**
     * @Fields serialVersionUID
     */
    private static final long serialVersionUID = -3868224883071039992L;

    public static void main(String[] args) {
        new MenuFrame();
    }

    public void initComp() {
        /** 声明组件 */
        JMenuBar menuBar = new JMenuBar();
        // 菜单组
        JMenu menuFile = new JMenu("文件");
        JMenu menuEdit = new JMenu("编辑");
        JMenu menuView = new JMenu("查看");
        // 菜单项
        JMenuItem itemFileNew = new JMenuItem("新建");
        JMenuItem itemFileOpen = new JMenuItem("打开");
        JMenuItem itemFileExit = new JMenuItem("退出");
        JMenuItem itemEditFind = new JMenuItem("查找");
        JMenuItem itemViewShow = new JMenuItem("显示");
        // 单选框
        ButtonGroup group = new ButtonGroup();
        JRadioButtonMenuItem radio1 = new JRadioButtonMenuItem("简单：单一花色");
        JRadioButtonMenuItem radio2 = new JRadioButtonMenuItem("中级：双花色");
        JRadioButtonMenuItem radio3 = new JRadioButtonMenuItem("高级：四花色");
    
        /** 设置组件 */
        radio1.setSelected(true);
        group.add(radio1);
        group.add(radio2);
        group.add(radio3);
        
        /** 添加组件 */
        menuFile.add(itemFileNew);
        menuFile.add(itemFileOpen);
        menuFile.addSeparator();
        menuFile.add(radio1);
        menuFile.add(radio2);
        menuFile.add(radio3);
        menuFile.addSeparator();
        menuFile.add(itemFileExit);
        menuEdit.add(itemEditFind);
        menuView.add(itemViewShow);
        menuBar.add(menuFile);
        menuBar.add(menuEdit);
        menuBar.add(menuView);
        this.setJMenuBar(menuBar);
    }
}
